﻿using System.Windows;
using System.Windows.Controls;
using Window = HandyControl.Controls.Window;

namespace YY.Admin.Views
{
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
            this.Closed += MainWindow_Closed;
        }

        private void MainWindow_Closed(object? sender, EventArgs e)
        {
            Application.Current.Shutdown();
        }

        private void UserMenuButton_Click(object sender, RoutedEventArgs e)
        {
            if (sender is Button button && button.ContextMenu != null)
            {
                button.ContextMenu.PlacementTarget = button;
                button.ContextMenu.IsOpen = true;
            }
        }

        private void Splitter_DragDelta(object sender, System.Windows.Controls.Primitives.DragDeltaEventArgs e)
        {
            double newWidth = LeftMenuTree.Width + e.HorizontalChange;

            // 获取主窗口宽度
            double windowWidth = this.ActualWidth;

            // 最小宽度
            double minWidth = 50;

            // 最大宽度
            double maxWidth = windowWidth - LeftSidebar.Width - GridSplitter.Width - minWidth;

            if (newWidth < minWidth)
                newWidth = minWidth;
            else if (newWidth > maxWidth)
                newWidth = maxWidth;

            LeftMenuTree.Width = newWidth;
        }
    }
}